package com.cqie.practicaltraining.controller;

import com.cqie.practicaltraining.config.result.R;
import com.cqie.practicaltraining.dto.DataSelectDto;
import com.cqie.practicaltraining.service.impl.DatasServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/data")
@Api(value = "数据管理")
public class dataController {
    @Autowired
    private DatasServiceImpl datasService;

    @PostMapping("/searchDataByCondition")
    @ApiOperation(value = "条件查询数据")
    public R searchDataByCondition(@RequestBody @Validated DataSelectDto dataSelectDto){
        return datasService.searchDataByCondition(dataSelectDto);
    }

    @PostMapping("/saveData")
    @ApiOperation(value = "保存数据")
    public R saveData(@RequestParam String dataName, @RequestParam Long typeId){
        return datasService.saveData(dataName, typeId);
    }

    @PutMapping("/updateDataStatus")
    @ApiOperation(value = "更新数据状态")
    public R updateDataStatus(@RequestParam Long dataId){
        return datasService.updateDataStatus(dataId);
    }

    @GetMapping("/getAllData")
    @ApiOperation(value = "获取所有数据")
    public R getAllData(){
        return datasService.getAllData();
    }
}
